<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="father">
        <div class="child">
            child
        </div>
    </div>
</body>
<style>
    .father {
        width: 200px;
        height: 200px;
        border: 1px solid red;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .child {
        width: 100px;
        height: 100px;
        border: 1px solid blue;

    }
</style>
<script>
    let father = document.getElementsByClassName('father')[0];
    let child = document.getElementsByClassName('child')[0]
    // father.addEventListener('click',(event)=>{
    //     console.log('father')
    // },true)
    // child.addEventListener('click',(event)=>{
    //     console.log('child')
    // },true)
    if ('serviceWorker' in navigator) {
        /* 当页面加载完成就创建一个serviceWorker */
        window.addEventListener('load', function () {
            /* 创建并指定对应的执行内容 */
            /* scope 参数是可选的，可以用来指定你想让 service worker 控制的内容的子目录。 在这个例子里，我们指定了 '/'，表示 根网域下的所有内容。这也是默认值。 */
            navigator.serviceWorker.register('./serviceWorker.js', { scope: './' })
                .then(function (registration) {
                    console.log('ServiceWorker registration successful with scope: ', registration.scope);
                })
                .catch(function (err) {
                    console.log('ServiceWorker registration failed: ', err);
                });
        });
    }
</script>

</html>